<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('消费者列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <input name="type" value="cloudCard" type="hidden">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>所属合作商：</label>
                                <select name="pid" th:with="type=${@dwl.getType('sys_user')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>用户状态：</label>
                                <select name="status" th:with="type=${@dict.getType('enableStatus')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="createCloudCard()" shiro:hasPermission="biz:customer:add">
                    <i class="fa fa-plus"></i> 录入云卡
                </a>
<!--                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="biz:customer:edit">-->
<!--                    <i class="fa fa-edit"></i> 修改-->
<!--                </a>-->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="biz:customer:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="biz:customer:export">
                    <i class="fa fa-download"></i> 导出
                </a>
                <br/>
                <div id="clcn" class="col-sm-12 select-table table-striped" style="width: 600px;margin-top: 10px;display: none;">
                    <br/>
                    <ul>
                        <li>
                            <label>云卡号(<span style="color: red;">* 请使用刷卡机刷卡或者手动输入卡号</span>)：</label>
                            <input maxlength="10" onkeyup="saveCloudCard()"  style="width: 480px;" class="form-control" type="text" id="cloudCardNo"/>
                            <br/>
                            <div style="margin-left: 40%;">
                                <button  th:onclick="'javascript:closeClcn()'" class="btn btn-danger" type="button">关闭</button>
                            </div>
                        </li>
                    </ul>
                </div>

            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: bootstrap-table-fixed-columns-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('biz:customer:edit')}]];
        var walletFlag = [[${@permission.hasPermi('biz:customer:wallet')}]];
        var removeFlag = [[${@permission.hasPermi('biz:customer:remove')}]];
        var realAuthStatusDatas = [[${@dict.getType('yesOrNo')}]];
        var userDatas = [[${@dwl.getType('sys_user')}]];
        var typeDatas = [[${@dict.getType('userType')}]];
        var sourceDatas = [[${@dict.getType('dataSource')}]];
        var statusDatas = [[${@dict.getType('enableStatus')}]];
        var prefix = ctx + "biz/customer";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/editCloudCard/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                fixedColumns: true,
                fixedRightNumber: 1,
                sortName: "id",
                sortOrder: "desc",
                modalName: "云卡",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: true
                },
                {
                    field: 'pid',
                    title: '合作商',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(userDatas, value);
                    }
                },
                {
                    field: 'openId',
                    title: '卡号',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'password',
                    title: '授权密码',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    },
                    visible: false
                },
                {
                    field: 'realName',
                    title: '真实姓名',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'idCardNo',
                    title: '身份证号',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'weixinId',
                    title: '微信ID',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    },
                    visible: false
                },
                {
                    field: 'phone',
                    title: '手机号',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'type',
                    title: '账户类型',
                    visible: false,
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(typeDatas, value);
                    }
                },
                {
                    field: 'source',
                    title: '来源',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(sourceDatas, value);
                    }
                },
                {
                    field: 'status',
                    title: '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(statusDatas, value);
                    }
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    field: 'updateTime',
                    title: '更新时间',
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value, 10, 'open');
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a style="margin-top: 3px;" class="btn btn-success btn-xs ' + walletFlag + '" href="javascript:void(0)" onclick="wallet(\'' + row.id + '\',\'' + row.realName + '\')"><i class="fa fa-yen"></i> 钱包</a> ');
                        actions.push('<a style="margin-top: 3px;" class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i> 编辑</a> ');
                        actions.push('<a style="margin-top: 3px;" class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i> 删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        /**
         * 钱包
         * @param id
         */
        function wallet(id,name){
            var url = ctx + '/biz/wallet?customerId=' + id;
            var title = id;
            if(name != undefined && name != null && name != ''){
                title = name;
            }
            title = "["+title+"]";
            $.modal.openTab("顾客"+title+"钱包", url);
        }

        /**
         * 创建云卡
         */
        function createCloudCard(){
            $("#clcn").show();
        }

        /**
         * 关闭云卡录入
         */
        function closeClcn(){
            $("#clcn").hide();
        }
        var singleFlag = false;
        /**
         * 云卡入库
         */
        function saveCloudCard(){
           var cloudCardNo = $("#cloudCardNo").val();
            console.log("cloudCardNo==",cloudCardNo);
            if(cloudCardNo.length != 10){
               console.log("卡号不符合规则，不进行创建");
               return;
            }
            if(singleFlag == false){
                singleFlag = true;
                //执行入库
                $.operate.post(prefix + "/create/cloudCard",{openId:cloudCardNo},function (result){
                    console.log(result);
                    if(result.code == 0){
                        $("#cloudCardNo").val("");
                    }
                    singleFlag = false;
                })
            }
        }
    </script>
</body>
</html>